﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.1f1
 *Date:           2019-03-18
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using UnityEditor;
using UnityEngine;
using System.IO;
using System;
namespace IFramework
{
    [InitializeOnLoad]
	public class CheckMCS
	{
       // [RuntimeInitializeOnLoadMethod]
        [InitializeOnLoadMethod]
        public static void Check()
        {
            string path = Application.dataPath;
#if UNITY_2018
            path = path.CombinePath("csc.rsp");
            PlayerSettings.allowUnsafeCode = true;
#else
            path = path.CombinePath("mcs.rsp");
#endif

            if (File.Exists(path)) return;
            string content = "-unsafe";
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(content);
                    fs.Flush();
                    sw.Flush();
                    sw.Close(); 
                    fs.Close();
                }
            }
            AssetDatabase.Refresh();
            EditorUtil.Restart();
        }
	}
}
